﻿using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;

public class JobSystem1 : MonoBehaviour {

	// Use this for initialization
	void Start () {
        NativeArray<float> result = new NativeArray<float>(1, Allocator.Temp);

        Job1 job1 = new Job1();
        job1.a = 1;
        job1.b = 2;
        job1.result = result;

        Debug.Log("开始 作业");
        JobHandle handle = job1.Schedule();

        Debug.Log("等待作业完成");
        handle.Complete();
        Debug.Log("作业完成");

        Debug.Log("结果 "+result[0]);

        float a = result[0];

        Debug.Log("释放内存 ");
        result.Dispose();
        Debug.Log("a 结果 " + a);
    }
	
}

public struct Job1 : IJob {
    public float a;
    public float b;
    public NativeArray<float> result;
    public void Execute() {
        result[0] = a + b;
    }
}
